﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;


public partial class FriendScene : Scene
{
	public enum TAB_TYPE
	{
		NONE = 0,
		DEAULT_FRIEND,
		REQUEST_FRIEND,
	}

	const int MAX_DELETE_FRIENDS_COUNT = 2;

	public UILabel offFriendCountLabel;
	public UILabel onFriendCountLabel;

	[HideInInspector] public TAB_TYPE currentTab = TAB_TYPE.NONE;
	
	public override void StartScene()
	{
		SelectTab(TAB_TYPE.DEAULT_FRIEND);

		offFriendCountLabel.text = "0";
		onFriendCountLabel.text = "0";
	}

	void SelectTab(TAB_TYPE selectTab)
	{
		Debug.Log ("SelectTab");
		if ( currentTab == selectTab )
			return;

		currentTab = selectTab;

		switch (selectTab)
		{
		case TAB_TYPE.DEAULT_FRIEND:
			LoadDefaultFriend(true);
			defaultFriendPanel.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
			requestFriendPanel.transform.localPosition = new Vector3(9999.0f, 0.0f, 0.0f);
			break;

		case TAB_TYPE.REQUEST_FRIEND:
			LoadRequestFriend(true);
			defaultFriendPanel.transform.localPosition = new Vector3(9999.0f, 0.0f, 0.0f);
			requestFriendPanel.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
			break;
		}
	}

	void ShowBadge(BadgeType badgeType)
	{
		NetworkManager.Instance.C2S_ALRAMCOUNT_CLEAR((int)badgeType, (wapperResponseData) => {
			NetworkManager.Instance.C2S_LEGION_GET((responseData) => {
				UserData.Instance.userModel = responseData.data;
				int newFriendBadgeCount = (int)(UserData.Instance.userModel.newAlarmCount & 1023);
				int requestFriendBadgeCount = (int)(UserData.Instance.userModel.newAlarmCount >> 10 & 1023);
				
				EPLog.Log ("newFriendBadgeCount : " + newFriendBadgeCount);
				EPLog.Log ("requestFriendBadgeCount : " + requestFriendBadgeCount);
				
				if (newFriendBadgeCount > 0)
				{
					defaultFriendBadge.badgeCount = newFriendBadgeCount;
					NGUITools.SetActive(defaultFriendBadge.gameObject, true);
				}
				else
				{
					NGUITools.SetActive(defaultFriendBadge.gameObject, false);
				}
				
				if (requestFriendBadgeCount > 0)
				{
					requestFriendBadge.badgeCount = requestFriendBadgeCount;
					NGUITools.SetActive(requestFriendBadge.gameObject, true);
				}
				else
				{
					NGUITools.SetActive(requestFriendBadge.gameObject, false);
				}
			});
		});
	}

	public void OnClick_CloseAll()
	{
		PopupUtility.PopAll();
	}
}